package com.geek.factory.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.geek.factory.entity.Material;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 原料基础信息表 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2025-06-23
 */
public interface MaterialMapper extends BaseMapper<Material> {

    @Select("SELECT quantity FROM material WHERE id = #{materialId}")
    Integer selectQuantityById(@Param("materialId") Long materialId);

    @Update("UPDATE material SET quantity = quantity + #{quantity} WHERE id = #{materialId}")
    void increaseQuantity(@Param("materialId") Long materialId, @Param("quantity") Integer quantity);

    @Update("UPDATE material SET quantity = quantity - #{quantity} WHERE id = #{materialId} AND quantity >= #{quantity}")
    int decreaseQuantity(@Param("materialId") Long materialId, @Param("quantity") Integer quantity);
}
